import { Injectable } from '@angular/core';

import { TranslateService } from '@ngx-translate/core';
import { ToasterService} from 'angular2-toaster';

@Injectable()
export class ControlToasterService {

  constructor(private translate: TranslateService, private toaster: ToasterService) { }

  popKnownError ({status, message}) {
    let result;
    switch (status) {
      case undefined:
            result = 'UnknownErrorTip';
            break;
      case 500:
            result = 'InternalServerErrorTip';
            break;
      case 404:
            result = 'NotFoundTip';
            break;
    }
    if (!result) {
      return;
    }
    this.translate.get(result).subscribe((str) => {
      this.toaster.pop('error', '', str);
    });
  }

  popWarning (message, params = {}) {
    this.translate.get(message.toString(), params).subscribe((str) => {
      this.toaster.pop('warning', '', str);
    });
  }
}
